package main

import (
	"fmt"
	"math/rand"
	"time"

	"github.com/360EntSecGroup-Skylar/excelize"
)

func main() {

	xlsx, err := excelize.OpenFile("3.xlsx")
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	if err != nil {
		fmt.Println(err)
	}

	biao := make(map[int]map[int][]string)

	for i := 1; i <= len(xlsx.GetSheetMap()); i++ {

		sheet := xlsx.GetSheetMap()[i]
		row := make(map[int][]string)

		for a := 0; a < len(xlsx.GetRows(sheet)); a++ {

			row[a] = xlsx.GetRows(sheet)[a]
		}

		biao[i] = row

	}

	for {

		b := r.Intn(3)      // 随机出一个表
		l := len(biao[b+1]) // 获得表的总数
		num := (biao[b+1][r.Intn(l)])
		sheet := xlsx.GetSheetName(b + 1)
		if sheet != "003-判断题" {
			fmt.Printf(sheet)
			fmt.Println("\n======================================================================================")
			fmt.Println(num[0], num[1])
			fmt.Printf("A.%s\nB.%s\nC.%s\nD.%s", num[2], num[3], num[4], num[5])
			fmt.Printf("\n======================================================================================\n")
			//fmt.Println(rows[6])
			var answer string
			fmt.Printf("请输入答案：")
			fmt.Scanf("%s", &answer)
			if answer == num[6] {
				fmt.Println("回答正确")
			} else {
				fmt.Println("回答错误")
				fmt.Println(num[6])
			}
			fmt.Printf("\n\n")
		} else {
			fmt.Println("\n=========================")
			fmt.Println(sheet)
			fmt.Println(num[0], num[1])
			fmt.Println("\n=========================")
			var answer string
			fmt.Printf("请输入答案（1-对,0-错）：")
			fmt.Scanf("%s", &answer)
			if answer == num[2] {
				fmt.Println("回答正确")
			} else {
				fmt.Println("回答错误")
				fmt.Println(num[2])
			}
			fmt.Printf("\n\n")
		}
	}

	/*
		var file []string

		files, _ := ioutil.ReadDir("./")
		for _, f := range files {
			s := strings.Split(f.Name(), ".")
			if s[1] == "xlsx" {
				file = append(file, f.Name())
			}
		}
		print(file)
	*/
}
